<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>人员管理</title>
  <link rel="stylesheet" href="../layui/css/layui.css">
  <script src="../layui/layui.js"></script>
  <link rel="stylesheet" href="../css/basic.css">
  <style>
    .btn-wrap{
      margin:5px 20px;
    }
    .btn-wrap>button{
      float: right;
      margin: 0 10px;
    }  
  </style>
</head>

<body>
  <div class="layui-col-sm8 layui-col-sm-offset2">
      <div class="btn-wrap layui-clear">
        <button id="addCounter" class="add-counter layui-btn layui-btn-normal">添加社团人员</button>
      </div>
    <table id="table" lay-filter="table"></table>
  </div>
</body>

<!--添加柜员信息-->
<form id="addNumber" class="layui-form bs-hidden fm-in" lay-filter="addNumber">
  <div class="layui-form-item">
      <label class="layui-form-label">学号：</label>
      <div class="layui-input-block">
          <input type="text" name="stu_no" required  lay-verify="required" autocomplete="off" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
          <div class="layui-input-block btn-center">
              <button class="layui-btn" lay-submit lay-filter="addPwd">提交</button>
              <button type="reset" class="layui-btn layui-btn-primary">重置</button>
          </div>
  </div>
</form>


<!--修改社团人员信息-->
<form id="updateNumber" class="layui-form bs-hidden fm-in" lay-filter="updateNumber">
  <div class="layui-form-item">
      <label class="layui-form-label">学号：</label>
      <div class="layui-input-block">
          <input type="text" id="stu_noBack" name="stu_noBack" required  lay-verify="required"  readonly  autocomplete="off" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
      <label class="layui-form-label">姓名：</label>
      <div class="layui-input-block">
      <input type="text" id="stu_nameBack" name="stu_nameBack" required  lay-verify="required" placeholder="请输入姓名"  autocomplete="off" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
      <label class="layui-form-label">性别：</label>
      <div class="layui-input-block">
        <input type="text" id="stu_sexBack" name="stu_sexBack" required  lay-verify="required" placeholder="请输入性别" autocomplete="off" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
      <label class="layui-form-label">年龄：</label>
      <div class="layui-input-block">
          <input type="text" id="stu_ageBack" name="stu_ageBack" required  lay-verify="required" placeholder="请输入年龄" autocomplete="off" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
      <label class="layui-form-label">电话：</label>
      <div class="layui-input-block">
        <input type="text" id="stu_telBack" name="stu_telBack" required  lay-verify="required|phone|number" placeholder="请输入电话" autocomplete="off" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
      <label class="layui-form-label">年级：</label>
      <div class="layui-input-block">
      <input type="text" id="stu_formBack" name="stu_formBack" required  lay-verify="required" placeholder="请输入你的年级" autocomplete="off" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
      <label class="layui-form-label">学院：</label>
      <div class="layui-input-block">
      <input type="text" id="stu_schoBack" name="stu_schoBack" required  lay-verify="required" placeholder="请输入你的学院" autocomplete="off" class="layui-input">
      </div>
  </div>
  <div class="layui-form-item">
        <div class="layui-input-block btn-center">
            <button class="layui-btn" lay-submit lay-filter="updatePwd">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
  </div>
</form>


<span class="bs-hidden" id="Sid"></span>
<!-- 表格里的操作按钮 -->
<script type="text/html" id="ipts">
  <a lay-event="edit" class="layui-btn layui-btn-xs">编辑</a>
  <a lay-event="del" class="layui-btn layui-btn-xs">删除</a>
</script>


<script>
layui.use(['laydate','table', 'layer', 'jquery','form'], function () {
  var laydate = layui.laydate;
  var table = layui.table
  var layer = layui.layer
  var $ = layui.jquery
  var form = layui.form;
  var mydate = new Date()
  var dataNow = mydate.toLocaleDateString()
  $.ajax({
   	type:"POST",
   	url:"/user/getManUser",
   	dataType:"json",
   	error:function(){
   		console.log("error!");
   	},
   	success:function(data){
   		console.log(data);
   		$('#Sid').html(data.soc_no);
   	//	alert($('#Sid').text());
   		ajaxNO1();
   	}
   })
function  ajaxNO1(){
  $.ajax({
	  type:"GET",
	  url:'/manager/serchSocietyNumber',
	  data:{"soc_no":$('#Sid').text()},//等写好登录记得更改
	  error:function(){
		  alert("error!---说明服务器返回失败");
	  },
	  dataType:"json",
	  success:function(dataGet){
		  console.log(dataGet)
		  showTable(dataGet);
	  }
  })
}
  

function showTable(tableData){
  //第一个实例
  table.render({
    id: 'tableImp',
    elem: '#table',
    page: true,//开启分页
    cols: [
        [ //表头
          {
            field: 'stu_no',
            title: '学号',
            width: '15%',
            sort: true,
         //   fixed: 'left',
            align: 'center'
          }, {
            field: 'stu_name',
            title: '姓名',
            width: '15%',
            align: 'center'
          }, {
            field: 'stu_sex',
            title: '性别',
            width: '6%',
            align: 'center',
            sort: true
          }, {
            field: 'stu_age',
            title: '年龄',
            width: '6%',
            align: 'center'
          },  {
            field: 'stu_tel',
            title: '电话',
            width: '10%',
            align: 'center'
          },{
            field: 'stu_form',
            title: '年级',
            width: '10%',
            align: 'center'
          },{
              field: 'stu_scho',
              title: '院校',
              width: '20%',
              align: 'center'
            },{
            fixed: 'right',
            title: '操作',
            align: 'center',
            width: '18%',
            toolbar: '#ipts'
          }
        ]
      ]
      //加载数据
     ,data: tableData
    ,done: function(res, curr, count){
        //如果是异步请求数据方式，res即为你接口返回的信息。
        //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
        //console.log(res);
        //得到当前页码
        //console.log(curr);
        //得到数据总量
        //console.log(count);
        }
  })
 }
  table.on('tool(table)',function (obj) {  
    var event = obj.event
	
    if(event === 'edit') {
      layer.open({
        type: 1,
        closeBtn: 1,
        title: '修改社员信息',
        content: $('#updateNumber'),
        area: ['800px', '600px'],
        offset: '10px',
        success:function (layero, index){
        	//console.log(layero, index);
        	console.log(obj.data.stu_age);
        	$('#stu_noBack').val(obj.data.stu_no);
        	$('#stu_nameBack').val(obj.data.stu_name);
        	$('#stu_sexBack').val(obj.data.stu_sex);
        	$('#stu_ageBack').val(obj.data.stu_age);
        	$('#stu_telBack').val(obj.data.stu_tel);
        	$('#stu_formBack').val(obj.data.stu_form);
        	$('#stu_schoBack').val(obj.data.stu_scho);
//        	$.get('/manager/changeNumberMessage',$('#updateNumber').serialize(),function(res){
//        		
//        	},"json")
        },
      })
    }
    //删除
    else if(event === 'del') {
        layer.open({
          type:1,
          closeBtn: 0,
          title:"提示信息",
          content:"<span style='font-size:20px; margin-left:40px'>"+"真的要删除么？"+"</span>",
          area:['200px','150px'],
          offset: '10px',
          btn:['确定','取消'],
          btnAlign:'c',
          yes:function(index, layero){
          	$.ajax({
        		type:"POST",
        		url:"/manager/deleteSocietyNumber",
        		data:{
        			stu_no:obj.data.stu_no,
        			soc_no:$('#Sid').text()
        		},
        		dataType:"json",
        		error:function(){
        			alert("error!");
        		},
        		success:function(data){
        			if(data == true){
        				layer.msg('删除成功!',{
        					time:1000
        				},function(){
        					layer.closeAll();
        				});
        				ajaxNO1();
        				return false;
        			}else if(data == false){
        				layer.msg('删除失败!',{
        					time:1000
        				},function(){
        					layer.closeAll();
        				});
        				ajaxNO1();
        				return false;
        			}
        		}	
        	})
          },
          btn2:function(index, layero){
              layer.close(index);
              return false;
          }
        })
    }
  })

  //新增
  $('#addCounter').click(function () {
    layer.open({
          title:'添加柜员信息',
          type:1,
          content:$('#addNumber'),
          area:['400px','300px'],
      });
  });

  
//监听sex
	var Ssex;
	form.on('radio(stu_sex)', function(data){
		console.log(data.elem); //得到radio原始DOM对象
		console.log(data.value); //被点击的radio的value值
		Ssex = data.value;
	});
	
//监听修改的提交
form.on('submit(updatePwd)', function(data){
	  console.log(data.field);
  	$.ajax({
  		type:"GET",
  		url:"/manager/changeNumberMessage",
  		data:{
  			stu_no:data.field.stu_noBack,
  			stu_name:data.field.stu_nameBack,
  			stu_sex:data.field.stu_sexBack,
  			stu_age:data.field.stu_ageBack,
  			stu_tel:data.field.stu_telBack,
  			stu_form:data.field.stu_formBack,
  			stu_scho:data.field.stu_schoBack
  		},
  		dataType:"json",
  		error:function(){
  			alert("error!");
  		},
  		success:function(data){
    		console.log(data);
    		if(data == true){
    			layer.msg('编辑成功!',{
    				time:1000
    			},function(){
    				layer.closeAll();
    			});
    			ajaxNO1();
    			return false;
    		}else if(data == false){
    			layer.msg('编辑失败!',{
    				time:1000
    			},function(){
    				layer.closeAll();
    			});
    			ajaxNO1();
    			return false;
    		}
  		}
  	})
    return false;
  });
//监听添加的提交
  form.on('submit(addPwd)', function(data){
	  console.log(data.field);
  	$.ajax({
  		type:"GET",
  		url:"/manager/insertSocietyNumber",
  		data:{
  			stu_no:data.field.stu_no,
  			soc_no:$('#Sid').text()//写好登录更改
  		},
  		dataType:"json",
  		error:function(){
  			alert("该社员已经进入社团或没有此成员！");
  		},
  		success:function(data){
    		console.log(data);
    		if(data == true){
    			layer.msg('添加成功!',{
    				time:1000
    			},function(){
    				layer.closeAll();
    			});
    			ajaxNO1();
    			return false;
    		}else if(data == false){
    			layer.msg('添加失败!',{
    				time:1000
    			},function(){
    				layer.closeAll();
    			});
    			ajaxNO1();
    			return false;
    		}
  		}
  	})
    return false;
  });


//执行一个laydate实例
laydate.render({
  elem: '#Ctime' //指定元素
});

})
</script>

<script>
!function(){function n(n,e,t){return n.getAttribute(e)||t}function e(n){return document.getElementsByTagName(n)}function t(){var t=e("script"),o=t.length,i=t[o-1];return{l:o,z:n(i,"zIndex",-1),o:n(i,"opacity",.9),c:n(i,"color","0,0,0"),n:n(i,"count",99)}}function o(){a=m.width=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,c=m.height=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}function i(){r.clearRect(0,0,a,c);var n,e,t,o,m,l;s.forEach(function(i,x){for(i.x+=i.xa,i.y+=i.ya,i.xa*=i.x>a||i.x<0?-1:1,i.ya*=i.y>c||i.y<0?-1:1,r.fillRect(i.x-.5,i.y-.5,1,1),e=x+1;e<u.length;e++)n=u[e],null!==n.x&&null!==n.y&&(o=i.x-n.x,m=i.y-n.y,l=o*o+m*m,l<n.max&&(n===y&&l>=n.max/2&&(i.x-=.03*o,i.y-=.03*m),t=(n.max-l)/n.max,r.beginPath(),r.lineWidth=t/2,r.strokeStyle="rgba("+d.c+","+(t+.2)+")",r.moveTo(i.x,i.y),r.lineTo(n.x,n.y),r.stroke()))}),x(i)}var a,c,u,m=document.createElement("canvas"),d=t(),l="c_n"+d.l,r=m.getContext("2d"),x=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(n){window.setTimeout(n,1e3/45)},w=Math.random,y={x:null,y:null,max:2e4};m.id=l,m.style.cssText="position:fixed;top:0;left:0;z-index:"+d.z+";opacity:"+d.o,e("body")[0].appendChild(m),o(),window.onresize=o,window.onmousemove=function(n){n=n||window.event,y.x=n.clientX,y.y=n.clientY},window.onmouseout=function(){y.x=null,y.y=null};for(var s=[],f=0;d.n>f;f++){var h=w()*a,g=w()*c,v=2*w()-1,p=2*w()-1;s.push({x:h,y:g,xa:v,ya:p,max:6e3})}u=s.concat([y]),setTimeout(function(){i()},100)}();
</script>
</html>

